cmake_minimum_required(VERSION 3.18.1)

option(USE_BIGNUM "" ON)

project(quickjs)

# 定义共享库
add_library(
        quickjs
        SHARED
        ""
)

target_sources(quickjs PRIVATE quickjs/quickjs-libc.c quickjs/quickjs.c quickjs/libregexp.c quickjs/libunicode.c quickjs/cutils.c)

target_include_directories(quickjs PRIVATE quickjs)

add_library(
        quickjs_wrapper
        SHARED
        quickjs_wrapper.cpp
)

file(READ "quickjs/VERSION" quickjs_version_string)
string(REGEX REPLACE "[\r\n]" "" QUICKJS_VERSION "${quickjs_version_string}")
target_compile_definitions(quickjs PRIVATE CONFIG_VERSION="${QUICKJS_VERSION}" _GNU_SOURCE)

if(USE_BIGNUM)
    target_compile_definitions(quickjs PRIVATE CONFIG_BIGNUM)
    target_sources(quickjs PRIVATE quickjs/libbf.c quickjs/libbf.h)
endif()

# 包含头文件路径
include_directories(${QUICKJS_SRC_DIR})

# 链接 Android NDK log 库
find_library(
        log-lib
        log
)
target_link_libraries(
        quickjs
        ${log-lib}
)

target_link_libraries(
        quickjs_wrapper
        quickjs
        ${log-lib}
)